Skip to content

add a guide how to declare plugin typings #1042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2017

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Jul 24, 2017

I'm seeing some users struggling how to declare typings for plugins (e.g. vuejs/vue-class-component#128), especially the plugin that augments instance property/component options. I think it can be tricky because we have to use a feature that most of ts users may not know.

This PR adds an example code to do that. I think it would be helpful not only for plugin developers but also users that uses a plugin not include typings since they can know how to make it by themselves.

Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me.

/ping @HerringtonDarkholme @kaorun343

Copy link
Member

@HerringtonDarkholme HerringtonDarkholme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM!


## Declaring Types of Vue Plugins

Plugins may augment Vue's global/instance properties, component options and so on. For that case, augmenting type declaration is also needed to use plugins in TypeScript. Fortunately, there is a feature to augment an existing types that is called [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

augment appears three times in this paragraph, which reads quite wordy. Also augment is rather an abstract term, so it is quite hard for TypeScript new comers.

I would suggest change some verbs:

Plugins may add Vue's global/instance properties, component options and so on. For that case, type declaration also needs updates to make plugins code compile in TypeScript.

add and update explains what augment does before we introduce the TS feature. I think this should be clearer for ordinary Vue users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion 👍 Updated!

@chrisvfritz
Copy link
Contributor

@ktsn Looks great! I just made some small tweaks to the wording.

@chrisvfritz chrisvfritz merged commit d7b1cc3 into vuejs:master Jul 25, 2017
@ktsn ktsn deleted the typescript-plugin branch July 25, 2017 23:52
kazupon pushed a commit to kazupon/vuejs.org that referenced this pull request Oct 1, 2017
* add a guide how to declare plugin typings (vuejs#1042)

* add a guide how to declare plugin typings

* improve wording

* Slight tweak to working for declaring typescript types for plugins

* Translate declaring types of vue plugins

* Update the updated field in ts guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants